package top.hugo.generator.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.Log;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.hugo.common.constant.ReqTokenConstant;
import top.hugo.common.domain.R;
import top.hugo.generator.service.GpApiDataStorageService;
import top.hugo.redis.utils.RedisUtils;

import java.util.ArrayList;
import java.util.Map;

/**
 * 股票接口数据转发
 *
 * @author kuanghua|
 * @since 2023-11-13 10:58:29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("ths")
@SaIgnore
@Log4j2
public class GpController {

    private final GpApiDataStorageService gpApiDataStorageService;
    /**
     * 竞价一字板
     * @param jsonString
     * @return
     */
    @SaIgnore
    @GetMapping("limitBoard")
    public JSON limitBoard(String jsonString) {
        return gpApiDataStorageService.limitBoard(jsonString);
    }

    /**
     * 涨停票
     * @param date
     * @return
     */
    @SaIgnore
    @GetMapping("limit_up_pool")
    public JSON limit_up_pool(String date) {
        return gpApiDataStorageService.limit_up_pool(date);
    }
    /**
     * 涨停票
     * @param date
     * @return
     */
    @SaIgnore
    @GetMapping("limit_up_pools")
    public JSON limit_up_pools(String date) {
        return gpApiDataStorageService.limit_up_pools(date);
    }

    /*炸板票*/
    @SaIgnore
    @GetMapping("open_limit_pool")
    public JSON open_limit_pool(String date) {
        return gpApiDataStorageService.open_limit_pool(date);
    }






    /*涨停和炸板状态*/
    @SaIgnore
    @GetMapping("limit_up_change")
    public JSON limit_up_change() {
        return gpApiDataStorageService.limit_up_change();
    }


    /*冲刺涨停*/
    @SaIgnore
    @GetMapping("limit_up")
    public JSON limit_up(String date) {
        return gpApiDataStorageService.limit_up(date);
    }


    @SaIgnore
    //集合竞价接口
    @GetMapping("callWarn")
    public JSON callWarn(String jsonString) {
        return gpApiDataStorageService.callWarn(jsonString);
    }



    @SaIgnore
    //获取分时数据
    @GetMapping("getTradeDay")
    public JSON getTradeDay(String date) {
        return gpApiDataStorageService.getTradeDay(date);
    }


    @SaIgnore
    //获取分时数据
    @PostMapping ("setCacheObject")
    public R<Object> setCacheObject(@RequestBody Map<String,Object> map) {
        String key= (String) map.get("key");
        String value= (String) map.get("value");
        if (ObjectUtils.isEmpty(key) || ObjectUtils.isEmpty(value) ){
            log.info(key,value);
            throw new RuntimeException("缓存key值不能为空");
        }

        RedisUtils.setCacheObject(key,value);
        return R.ok();
    }

    @GetMapping ("getCacheObject")
    public R<String> getCacheObject(String key) {
        String cacheObject = RedisUtils.getCacheObject(key);
         if (ObjectUtils.isEmpty(cacheObject)){
            return R.ok(JSONUtil.toJsonStr(new ArrayList<>()));
        }
        return R.ok(cacheObject);
    }

    @SaIgnore
    //集合竞价接口
    @PostMapping("get_block_list")
    public JSON get_block_list(String jsonString) {
        return gpApiDataStorageService.get_block_list(jsonString);
    }


    @SaIgnore
    //集合竞价接口
    @PostMapping("get_stock_list_by_block")
    public JSON get_stock_list_by_block(String jsonString) {
        return gpApiDataStorageService.get_stock_list_by_block(jsonString);
    }


    @SaIgnore
    //i问财查询接口
    @PostMapping("get_robot_data")
    public JSON get_robot_data(String jsonString,String hexin) {
        return gpApiDataStorageService.get_robot_data(jsonString,hexin);
    }

    @SaIgnore
    //自选添加接口
    @PostMapping("self_stock_add_zx")
    public JSON self_stock_add_zx(String jsonString,String cookie) {
        return gpApiDataStorageService.self_stock_add_zx(jsonString,cookie);
    }

    @SaIgnore
    //自选添加接口
    @PostMapping("self_stock_add")
    public JSON self_stock_add(String jsonString,String cookie) {
        return gpApiDataStorageService.self_stock_add(jsonString,cookie);
    }
}
